package com.xbongbong.pro.message.pushset;/*/*/

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.message.domain.entity.PushSetEntity;
import com.xbongbong.pro.message.base.AbstractPushSet;
import com.xbongbong.pro.message.constant.PushSetConstant;
import com.xbongbong.pro.message.enums.PushObjectTypeEnum;
import com.xbongbong.pro.message.enums.PushTypeEnum;
import com.xbongbong.pro.message.model.PushSetModel;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

public class InvoiceRedPushSet extends AbstractPushSet{

    @Override
    public PushSetEntity toPushSetEntity(String pushObject, String pushTime, String attrEntity) {
        return null;
    }

    @Override
    public PushSetEntity getPushSet(String corpid, Integer subType, PushSetModel pushSetModel) {
        Integer type = PushTypeEnum.INVOICE_RED_ADD_PUSH.getCode();

        Map<String, Object> param = new HashMap<>(16);
        param.put("corpid", corpid);
        param.put("type", type);
        param.put("subType", subType);
        List<PushSetEntity> pushSetList = pushSetModel.findEntitys(param);

        PushSetEntity pushSetEntity;
        if (pushSetList.isEmpty()) {
            pushSetEntity = new PushSetEntity();
            pushSetEntity.setType(type);
            pushSetEntity.setSubType(subType);
            pushSetEntity.setEnable(0);

            JSONObject pushObject = new JSONObject();
            //type
            JSONArray typeArray = new JSONArray();
            JSONObject object = new JSONObject();
            object.put("name", PushObjectTypeEnum.MAINUSER.getName());
            object.put("alias", PushObjectTypeEnum.MAINUSER.getAlias());
            object.put("enable", 1);
            typeArray.add(object);
            JSONObject object1 = new JSONObject();
            object1.put("name", PushObjectTypeEnum.COLLABORATOR.getName());
            object1.put("alias", PushObjectTypeEnum.COLLABORATOR.getAlias());
            object1.put("enable", 0);
            typeArray.add(object1);
            JSONObject object2 = new JSONObject();
            object2.put("name", PushObjectTypeEnum.CONTRACT_SIGNING.getName());
            object2.put("alias", PushObjectTypeEnum.CONTRACT_SIGNING.getAlias());
            object2.put("enable", 1);
            typeArray.add(object2);
            pushObject.put("type", typeArray);
            //manager
            JSONObject managerObject = new JSONObject();
            managerObject.put("enable", 0);
            managerObject.put("value", new ArrayList<>());
            pushObject.put("manager", managerObject);
            //dep
            JSONObject depObject = new JSONObject();
            depObject.put("enable", 0);
            depObject.put("value", new ArrayList<>());
            pushObject.put("dep", depObject);
            //role
            JSONObject roleObject = new JSONObject();
            roleObject.put("enable", 0);
            roleObject.put("value", new ArrayList<>());
            pushObject.put("role", roleObject);
            //user
            JSONObject userObject = new JSONObject();
            userObject.put("enable", 0);
            userObject.put("value", new ArrayList<>());
            pushObject.put("user", userObject);

            pushSetEntity.setPushObject(pushObject.toJSONString());
        } else {
            pushSetEntity = pushSetList.get(0);
        }

        if (Objects.equals(PushTypeEnum.INVOICE_RED_ADD_PUSH.getSubCode(), subType)) {
            pushSetEntity.setTitle(PushTypeEnum.INVOICE_RED_ADD_PUSH.getName());
            pushSetEntity.setContent(I18nMessageUtil.getMessage(PushSetConstant.INVOICE_RED_ADD));

        }

        return pushSetEntity;
    }

    @Override
    public PushSetEntity getPushSet(String corpid, String attr, PushSetModel pushSetModel) {
        return null;
    }

    @Override
    public List<PushSetEntity> getPushSet(String corpid, List<String> attrList, PushSetModel pushSetModel, Long templateId) {
        return null;
    }

    @Override
    public JSONObject getTimeJson(JSONObject jsonObject) {
        return null;
    }
}
